require "dnd4"

let :Character, Entity.with(
  :strengh => Strength,
  :constitution => Constitution,
  :dexterity => Dexterity,
  :intelligence => Intelligenche,
  :wisdom => Wisdom,
  :charisma => Charisma,
  :ability_points => Integer
).having(
  :ability_points => 22
)


# All characters must start with their 6 scores equals to [8, 10, 10, 10, 10, 10]
Character.addRule(
  :r_ability_start,
  "abilities" => [:strength,
    :constitution,
    :dexterity,
    :intelligence,
    :wisdom,
    :charisma]) do |env|
    env["abilities"].filter{|a| a.get(:score) == 8}.size() == 1 &&
    env["abilities"].filter{|a| a.get(:score) == 10}.size() == 5
  end


# The ability points must remain positive
Character.addRule(:r_ability_points,
  "ability_points" => :ability_points,
  Proc.new { |env| env["ability_points"] >= 0  }
)

# Character creation console

Character.addAction(:increment_ability,
  Proc.new { |ability|  }
)

Character.addConsole(:c_create_char,
  setters(:strength, :constitution, :dexterity, :intelligence, :wisdom, :charisma),
  rules(:r_ability_start)
)

# Character initialization console
Character.addConsole(:c_char_init,
  "abilities" => [:strength, :constitution, :dexterity, :intelligence, :wisdom, :charisma]
)
